package org.qpcr.community.standalone.web.response.dashboard;

import lombok.Data;

import java.util.List;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

@Data
public class AlarmCountResp {
    private List<String> xData;
    private List<LevelSeries> series;

    public static AlarmCountResp createMockData(String periodType) {
        AlarmCountResp resp = new AlarmCountResp();
        List<String> xData = new ArrayList<>();
        int count = 1;
        if ("week".equalsIgnoreCase(periodType)) {
            count = 7;
        } else if ("month".equalsIgnoreCase(periodType)) {
            count = 30;
        }
        // 生成日期
        LocalDate today = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd");
        for (int i = count - 1; i >= 0; i--) {
            xData.add(today.minusDays(i).format(formatter));
        }
        resp.setXData(xData);

        // 生成series
        List<LevelSeries> seriesList = new ArrayList<>();
        LevelSeries level1 = new LevelSeries();
        level1.setName("级别1");
        level1.setColor("#F5222D");
        level1.setData(IntStream.range(0, count).map(i -> (int)(Math.random() * 10 + 5)).boxed().collect(Collectors.toList()));

        LevelSeries level2 = new LevelSeries();
        level2.setName("级别2");
        level2.setColor("#FAAD14");
        level2.setData(IntStream.range(0, count).map(i -> (int)(Math.random() * 10 + 8)).boxed().collect(Collectors.toList()));

        seriesList.add(level1);
        seriesList.add(level2);
        resp.setSeries(seriesList);

        return resp;
    }
}